/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { TypeHandlerRegistry } from './TypeHandlerRegistry';
import { createPrimitiveHandlers } from './PrimitiveHandler';
import { createGenericContainerHandlers } from './GenericContainerHandler';
import { createUnionTypeHandlers } from './UnionTypeHandler';
import { createEnumHandler } from './EnumHandler';
import { createGenericHandler } from './GenericHandler';
import { createCustomClassHandler } from './CustomClassHandler';
import { createTupleTypeHandlers } from './TupleHandler';
import { createDateHandler } from './DateHandler';
import { createDecimalHandler } from './DecimalHandler';

/**
 * 初始化类型处理器注册表
 * 注册所有内置的类型处理器
 */
export function initializeTypeHandlers(): TypeHandlerRegistry {
  const registry = TypeHandlerRegistry.getInstance();

  // 1. 注册基础类型处理器（6个Handler）
  registry.registerAll(createPrimitiveHandlers());

  // 2. 注册泛型容器处理器（7个Handler）
  registry.registerAll(createGenericContainerHandlers());

  // 3. 注册联合类型处理器（3个Handler）
  registry.registerAll(createUnionTypeHandlers());

  // 4. 注册枚举类型处理器（1个Handler）
  registry.register(createEnumHandler());

  // 5. 注册泛型参数处理器（1个Handler，优先级95，高于CustomClass）
  registry.register(createGenericHandler());

  // 6. 注册自定义类处理器（1个Handler，fallback，优先级最低）
  registry.register(createCustomClassHandler());

  // 7. 注册元组处理器（1个Handler）
  registry.register(createTupleTypeHandlers());

  // 8. 注册日期处理器（1个Handler）
  registry.register(createDateHandler());

  // 9. 注册其他处理器（如DecimalHandler）
  registry.registerAll([
    createDecimalHandler()
  ]);

  return registry;
}